package org.server;

import com.iohao.game.action.skeleton.ext.spring.ActionFactoryBeanForSpring;
import com.iohao.game.bolt.broker.client.AbstractBrokerClientStartup;
import com.iohao.game.bolt.broker.client.external.session.UserSessions;
import com.iohao.game.bolt.broker.server.BrokerServer;
import com.iohao.game.common.kit.ExecutorKit;
import com.iohao.game.simple.SimpleRunOne;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.server.external.ExternalServerReal;
import org.server.server.LoginLogicServer;
import org.server.server.RoomLogicServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;


import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.LongAdder;


/**
 * @author Admin
 * 服务器启动入口
 */
@Slf4j
@SpringBootApplication
public class GameApplication {

    public static void main(String[] args) {
        SpringApplication.run(GameApplication.class, args);
        startServer();
    }

    @Bean
    public ActionFactoryBeanForSpring actionFactoryBean() {
        // 将业务框架交给 spring 管理
        return ActionFactoryBeanForSpring.me();
    }

    public static void startServer() {
        // 游戏对外服端口
        int port = 10101;
        List<AbstractBrokerClientStartup> logicList = List.of(
                //登陆逻辑服
                new LoginLogicServer(),
                //房间逻辑服
                new RoomLogicServer()
        );

        // 启动 对外服、网关服、逻辑服; 并生成游戏业务文档
        SimpleRunOne runOne = new SimpleRunOne()
                .setExternalServer(ExternalServerReal.createExternalServer(port))
                .setBrokerServer(BrokerServer.newBuilder().build())
                .setLogicServerList(logicList);

        runOne.startup();
    }
}
